﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Crank.Core
{
    public class Preprocessor
    {
        private static IDictionary<string, Action<string[]>> directives;
        protected static IDictionary<string, Action<string[]>> Directives
        {
            get
            {
                return directives = directives ?? new Dictionary<string, Action<string[]>>();
            }
        }

        public static void AddDirective(string name, Action<string[]> action)
        {
            Directives[name.ToUpper()] = action;
        }

        public static void Process(string directive, string[] args)
        {
            directive = directive.ToUpper();
            if (Directives.ContainsKey(directive))
                Directives[directive](args);
        }

        public static void InstallDefaultDirectives()
        {
            DefaultOptionalityPreparser.Install();
            UncountablePreprocessor.Install();
            TypeAliasPreprocessor.Install();
            IrregularPreprocessor.Install();
            AliasPreprocessor.Install();
            IncludePreprocessor.Install();
        }
    }
}
